/*
 * HttpDownloader.h
 *
 *  Created on: 26.09.2012
 *      Author: Sergey
 */

#ifndef HTTPDOWNLOADER_H_
#define HTTPDOWNLOADER_H_

#include <QNetworkAccessManager>
#include <QUrl>
#include <QFile>

class HttpDownloader : public QObject {
	Q_OBJECT

public:
	HttpDownloader(QString url, QString directoryPath, QWidget *parent = 0);
	virtual ~HttpDownloader();

	bool downloadFile();

signals:
	void progressUpdated(int newProgress);
	void downloadFinished();

private:
	QUrl url;
	QString directoryPath;
	QNetworkAccessManager qnam;
	QNetworkReply *reply;
	QFile *file;
	bool httpRequestAborted;

	QWidget *parent;

private slots:
	void startDownload();
	void cancelDownload();
	void httpFinished();
	void httpReadyRead();
	void updateDataReadProgress(qint64 bytesRead, qint64 totalBytes);

};

#endif /* HTTPDOWNLOADER_H_ */
